home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / gfx / opal / devdocs.lha / Examples / show24.c < prev   
C/C++ Source or Header  |  1993-05-04  |  9KB  |  402 lines

  1. #include <opal/opallib.h>
  2. #include <workbench/icon.h>
  3. #include <workbench/workbench.h>
  4. #include <workbench/startup.h>
  5. #include <intuition/intuitionbase.h>
  6. #include <proto/all.h>
  7. #include <string.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10.  
  11.  
  12. #define VERSION "1.4"
  13.  
  14.     /* 2.0 style version string for the VERSION command */
  15. char Version[] = "\0$VER: Show24 " VERSION " (10.02.93)";
  16.  
  17. struct IntuitionBase *IntuitionBase;
  18. struct GfxBase *GfxBase;
  19. struct OpalBase *OpalBase;
  20. struct OpalScreen *OScrn;
  21. struct WBArg *WBArg;
  22. BOOL FromWB;
  23. UBYTE *Button = (UBYTE *)0xbfe001;        /* Nasty */
  24.  
  25. #define OR ||
  26. #define AND &&
  27.  
  28. char Banner[] = "Show24 V"VERSION" by Martin Boyd, ©1992 Opal Technology Pty Ltd.\n";
  29.  
  30. void Show_Pic (char *Name);
  31. void Clean_Up (char *String,int RetCode);
  32. char *WB_Arg (void);
  33. int Num_WB_Args (struct WBStartup *ArgMsg);
  34.  
  35. void Open_BGScreen (void);
  36. void Close_BGScreen (void);
  37. static struct Screen *BGScrn;
  38.  
  39. void App_Wait (void);
  40. void Error_Msg (char *String);
  41.  
  42.  
  43. void main (int argc,char *argv[])
  44. {
  45.    int i,NumArgs;
  46.    char *Name;
  47.  
  48.     if (argc==0)
  49.         { NumArgs = Num_WB_Args ((struct WBStartup *)argv);
  50.           FromWB = TRUE;
  51.         }
  52.     else
  53.         NumArgs = argc-1;
  54.  
  55.     if (!FromWB)
  56.         puts (Banner);
  57.  
  58.     GfxBase = (struct GfxBase *) OpenLibrary ("graphics.library",0L);
  59.     IntuitionBase = (struct IntuitionBase *) OpenLibrary ("intuition.library",0L);
  60.     if ((GfxBase==NULL) OR (IntuitionBase==NULL))
  61.         Clean_Up (NULL,10);
  62.  
  63.     OpalBase = (struct OpalBase *) OpenLibrary ("opal.library",0L);
  64.     if (OpalBase==0L)
  65.         Clean_Up ("Can't open opal.library\n",10);
  66.     OScrn = NULL;
  67.  
  68.     if ((FromWB) AND (NumArgs==0))
  69.         { App_Wait();
  70.           Clean_Up (NULL,0);
  71.         }
  72.  
  73.     if (NumArgs<1)
  74.         Clean_Up ("Usage: Show24 File\n",0);
  75.  
  76.  
  77.     for (i=1; i<=NumArgs; i++)
  78.         { if (FromWB)
  79.             Name = WB_Arg();
  80.           else
  81.             Name = argv[i];
  82.           Show_Pic (Name);
  83.         }
  84.  
  85.     Clean_Up (NULL,0);
  86. }
  87.  
  88.  
  89. void Show_Pic (char *Name)
  90. {
  91.    long Err;
  92.  
  93.     Err = LoadImage24 (NULL,Name,VIRTUALSCREEN24);
  94.     if (Err < OL_ERR_MAXERR)
  95.         { if (Err==OL_ERR_OPENFILE)
  96.             Error_Msg ("Error opening file!!");
  97.           else if ((Err==OL_ERR_NOTILBM) OR (Err==OL_ERR_BADIFF)
  98.             OR (Err==OL_ERR_FORMATUNKNOWN))
  99.             Error_Msg ("Not a recognised file format!!");
  100.           else if (Err==OL_ERR_OUTOFMEM)
  101.             Error_Msg ("Out of memory!!\n");
  102.           else if (Err==OL_ERR_CTRLC)
  103.             Error_Msg ("Aborted");
  104.           else
  105.             Error_Msg ("Error displaying image!!");
  106.           return;
  107.         }
  108.     if (BGScrn==NULL)
  109.         Open_BGScreen ();
  110.     OScrn = (struct OpalScreen *) Err;
  111.     Err = (long)LowMemUpdate24 (OScrn,0);
  112.     if ((Err>OL_ERR_MAXERR) AND (!(OScrn->Flags&ILACE24)))
  113.         { AutoSync24 (TRUE);
  114.           Err = (long)LowMemUpdate24 (OScrn,6);
  115.         }
  116.     FreeScreen24 (OScrn);
  117.     if (Err < OL_ERR_MAXERR)
  118.         { CloseScreen24 ();
  119.           if (Err==OL_ERR_OUTOFMEM)
  120.             Error_Msg ("Out of memory!!");
  121.           else if (Err==OL_ERR_CANTCLOSE)
  122.             Error_Msg ("OpalVision Display in Use.");
  123.           else
  124.             Error_Msg ("Error Displaying image!!");
  125.           return;
  126.         }
  127.     AutoSync24 (TRUE);
  128.     while (!(*Button & (1<<6)));
  129.     while (*Button & (1<<6));
  130.  
  131.     CloseScreen24();
  132. }
  133.  
  134. int Num_WB_Args (struct WBStartup *ArgMsg)
  135. {
  136.     WBArg = ArgMsg->sm_ArgList;
  137.     return (ArgMsg->sm_NumArgs-1);
  138. }
  139.  
  140.  
  141. char *WB_Arg (void)
  142. {
  143.     WBArg++;
  144.     CurrentDir (WBArg->wa_Lock);
  145.     return (WBArg->wa_Name);
  146. }
  147.  
  148. void _abort (void)
  149. {
  150.     Clean_Up (NULL,0);
  151. }
  152.  
  153.  
  154. void Clean_Up (char *String,int RetCode)
  155. {
  156.  
  157.     if (OpalBase!=NULL)
  158.         { CloseScreen24 ();
  159.           CloseLibrary ((struct Library *)OpalBase);
  160.         }
  161.     if (String!=NULL)
  162.         Error_Msg (String);
  163.     Close_BGScreen ();
  164.     if (IntuitionBase!=NULL) CloseLibrary ((struct Library *)IntuitionBase);
  165.     if (GfxBase!=NULL) CloseLibrary ((struct Library *)GfxBase);
  166.     exit (RetCode);
  167. }
  168.  
  169.  
  170.  
  171. /*  Open a standard screen intuition so that it will function
  172.  * correctly with the AA chip set in multi sync mode.
  173.  */
  174.  
  175. struct TagItem ScreenTags[3] =
  176.     { { SA_DisplayID,NTSC_MONITOR_ID},
  177.       { SA_Draggable,FALSE},
  178.       { TAG_DONE,0 }
  179.     };
  180.  
  181. static struct ExtNewScreen BGNewScreen = {
  182.     0,0,320,2,1,(UBYTE)-1,(UBYTE)-1,0,
  183.     CUSTOMSCREEN|SCREENQUIET|NS_EXTENDED,
  184.     NULL,NULL,NULL,NULL,
  185.     ScreenTags
  186. };
  187.  
  188.  
  189. static USHORT BGPalette[] = { 0x0001 };
  190.  
  191. void Open_BGScreen (void)
  192. {
  193.    struct MonitorInfo MonitorInfo;
  194.    struct DisplayInfo DisplayInfo;
  195.    DisplayInfoHandle Handle;
  196.    ULONG ModeID;
  197.    LONG Result;
  198.  
  199.     if (IntuitionBase->LibNode.lib_Version<36) return;
  200.     ModeID = GetVPModeID (&IntuitionBase->FirstScreen->ViewPort);
  201.     Handle = FindDisplayInfo (ModeID);
  202.     Result = GetDisplayInfoData (Handle,(UBYTE *)&MonitorInfo,
  203.             sizeof (struct MonitorInfo),DTAG_MNTR,NULL);
  204.     Result = GetDisplayInfoData (Handle,(UBYTE *)&DisplayInfo,
  205.             sizeof (struct DisplayInfo),DTAG_DISP,NULL);
  206.  
  207.     /*  If line frequency if >15Khz, we must open
  208.      * a low scan rate frequency screen.
  209.      */
  210.  
  211.     if (MonitorInfo.TotalColorClocks<220)
  212.         { if (DisplayInfo.PropertyFlags & DIPF_IS_PAL)
  213.             { BGNewScreen.Height = 256;
  214.               ScreenTags[0].ti_Data = PAL_MONITOR_ID;
  215.             }
  216.           else
  217.             { BGNewScreen.Height = 200;
  218.               ScreenTags[0].ti_Data = NTSC_MONITOR_ID;
  219.             }
  220.           BGScrn = OpenScreen ((struct NewScreen *)&BGNewScreen);
  221.           if (BGScrn!=NULL)
  222.             LoadRGB4 (&BGScrn->ViewPort,BGPalette,1L);
  223.         }
  224. }
  225.  
  226. void Close_BGScreen (void)
  227. {
  228.     if (BGScrn!=NULL)
  229.         CloseScreen (BGScrn);
  230.     BGScrn = NULL;
  231. }
  232.  
  233.  
  234.  
  235. /* Start an AppIcon and wait for messages.
  236.  */
  237.  
  238. extern struct DiskObject AppObject;
  239. struct Library *WorkbenchBase;
  240.  
  241. BOOL Info_Req (void);
  242.  
  243.  
  244. void App_Wait (void)
  245. {
  246.    struct MsgPort *AppPort;
  247.    struct AppIcon *AppIcon;
  248.    struct AppMessage *AppMsg;
  249.    BPTR OldDir;
  250.    int i;
  251.  
  252.     WorkbenchBase = OpenLibrary ("workbench.library",36L);
  253.     if (WorkbenchBase==NULL) return;
  254.     AppPort = CreateMsgPort ();
  255.     if (AppPort==NULL)
  256.         { CloseLibrary (WorkbenchBase);
  257.           return;
  258.         }
  259.  
  260.     AppIcon = AddAppIconA (0,NULL,"Show24",AppPort,NULL,&AppObject,NULL);
  261.     if (AppIcon==NULL)
  262.         { DeleteMsgPort (AppPort);
  263.           CloseLibrary (WorkbenchBase);
  264.           return;
  265.         }
  266.  
  267.     /* Wait for App Messages */
  268.  
  269.     FOREVER
  270.         { WaitPort (AppPort);
  271.           while (AppMsg = (struct AppMessage *)GetMsg (AppPort))
  272.             { if (AppMsg->am_NumArgs==0L)
  273.                 { if (!Info_Req ())
  274.                     { RemoveAppIcon (AppIcon);
  275.                       DeleteMsgPort (AppPort);
  276.                       CloseLibrary (WorkbenchBase);
  277.                       return;
  278.                     }
  279.                 }
  280.               else if (AppMsg->am_NumArgs>0)
  281.                 { for (i=0; i<AppMsg->am_NumArgs; i++)
  282.                     { OldDir = CurrentDir (AppMsg->am_ArgList[i].wa_Lock);
  283.                       Show_Pic (AppMsg->am_ArgList[i].wa_Name);
  284.                       CurrentDir (OldDir);
  285.                     }
  286.                 }
  287.             }
  288.           Close_BGScreen ();
  289.         }
  290. }
  291.  
  292.  
  293.  
  294. char Banner2[] = "Show24 V"VERSION" ©1992 Opal Technology";
  295.  
  296. struct EasyStruct MyES = 
  297.     { sizeof (struct EasyStruct),
  298.       0,
  299.       (UBYTE *)Banner2,
  300.       (UBYTE *)"To display images, drop their\nicons onto this icon.\nTo Remove Show24 select quit.",
  301.       (UBYTE *)"Continue|Quit"
  302.     };
  303.  
  304.  
  305.  
  306.  
  307.  
  308. BOOL Info_Req (void)
  309. {
  310.    BOOL Res;
  311.  
  312.     if (IntuitionBase->LibNode.lib_Version<36)
  313.         return (TRUE);
  314.     Res = EasyRequestArgs (NULL,&MyES,NULL,NULL);
  315.     return (Res);
  316. }
  317.  
  318.  
  319. struct EasyStruct ErrorES = 
  320.     { sizeof (struct EasyStruct),
  321.       0,
  322.       (UBYTE *)Banner2,
  323.       NULL,
  324.       (UBYTE *)"OK"
  325.     };
  326.  
  327.  
  328. void Error_Msg (char *String)
  329. {
  330.  
  331.     if (String==NULL) return;
  332.     if (!FromWB)
  333.         { puts (String);
  334.           return;
  335.         }
  336.  
  337.     if (IntuitionBase->LibNode.lib_Version<36)
  338.         return;
  339.     ErrorES.es_TextFormat = (UBYTE *)String;
  340.     EasyRequestArgs (NULL,&ErrorES,NULL,NULL);
  341. }
  342.  
  343.  
  344. USHORT IconData[] = {
  345.     0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  346.     0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  347.     0x1FFF,0xFFFF,0xFC00,0x0000,0x1000,0x0000,0x0400,0x0000,
  348.     0x10AA,0xAABA,0x8400,0x0000,0x12AA,0xAAFA,0xA400,0x0000,
  349.     0x12AA,0xABFA,0xA40F,0x0700,0x12AA,0xAFFA,0xA41F,0x8F80,
  350.     0x12AA,0xBFFF,0xFF8D,0xDF80,0x12AA,0xBFFF,0xFFC3,0xFF80,
  351.     0x12AA,0xBFFF,0xFFC7,0xBFC0,0x12AA,0xAFFF,0xFFCF,0x1FE0,
  352.     0x12AA,0xABFA,0xA41F,0x8380,0x12AA,0xAAFA,0xA40F,0xC180,
  353.     0x10AA,0xAABA,0x8400,0x0000,0x1000,0x0000,0x0400,0x0000,
  354.     0x1FFF,0xFFFF,0xFC00,0x0000,0x007F,0x003F,0x8000,0x0000,
  355.     0x0100,0x0000,0x2000,0x0000,0x0200,0x0000,0x1000,0x0000,
  356.     0x03FF,0xFFFF,0xF000,0x0000,0x0000,0x0000,0x0000,0x0000,
  357.     0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  358.     0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  359.     0x0FFF,0xFFFF,0xF800,0x0000,0x0E00,0x0010,0x3800,0x0000,
  360.     0x0C00,0x0070,0x1800,0x0000,0x0C00,0x01F0,0x180F,0x0700,
  361.     0x0C00,0x07F0,0x1819,0x8F00,0x0C00,0x1FFF,0xFF81,0x9B00,
  362.     0x0C00,0x3FFF,0xFF83,0x3300,0x0C00,0x0FFF,0xFF86,0x3FC0,
  363.     0x0C00,0x03F0,0x000C,0x0300,0x0C00,0x00F0,0x181F,0x8300,
  364.     0x0C00,0x0030,0x1800,0x0000,0x0E00,0x0000,0x3800,0x0000,
  365.     0x0FFF,0xFFFF,0xF800,0x0000,0x0000,0x0000,0x0000,0x0000,
  366.     0x0000,0xFFC0,0x0000,0x0000,0x00FF,0xFFFF,0xC000,0x0000,
  367.     0x01FF,0xFFFF,0xE000,0x0000,0x0000,0x0000,0x0000,0x0000
  368. };
  369.  
  370. struct Image IconImage = {
  371.     0,0,
  372.     59,23,
  373.     2,
  374.     IconData,
  375.     0x0003,0x0000,
  376.     NULL
  377. };
  378.  
  379. struct DiskObject AppObject =
  380.     { NULL,
  381.       NULL,
  382.         { NULL,
  383.           0,0,
  384.           59,23,
  385.           NULL,
  386.           NULL,
  387.           NULL,
  388.           (APTR)&IconImage,
  389.           NULL,NULL,NULL,NULL,
  390.           NULL,NULL
  391.         },
  392.       NULL,
  393.       NULL,        /* NAME */
  394.       NULL,
  395.       NO_ICON_POSITION,
  396.       NO_ICON_POSITION,
  397.       NULL,
  398.       NULL,
  399.       NULL
  400.     };
  401.  
  402.